package sz.szsmk.citizencard.mvp.presenter;

import javax.inject.Inject;

import sz.szsmk.citizencard.DaggerApplication;
import sz.szsmk.citizencard.model.network.GsdxNetApi;
import sz.szsmk.citizencard.model.network.bean.request.IBaseRequest;
import sz.szsmk.citizencard.model.network.bean.response.GestureValidBean;
import sz.szsmk.citizencard.mvp.contract.IPasAdminContact;
import sz.szsmk.citizencard.retrofitrxjava.ErrorAction;
import sz.szsmk.citizencard.retrofitrxjava.NetworkDateSources;
import sz.szsmk.citizencard.retrofitrxjava.SubscribeResult;
import sz.szsmk.citizencard.util.ACache;
import sz.szsmk.citizencard.util.Constant;
import sz.szsmk.citizencard.util.StringUtils;

/**
 * Copyright (c)2019
 * author: zdh
 * created on: 2019/1/18 15:50
 * description:
 */
public class PsdAdminPresenter extends IBasePresenter
implements IPasAdminContact.IPsdAdminPresenter<IPasAdminContact.IPsdAdminView>{


    private NetworkDateSources mNetworkDateSource;
    GsdxNetApi gsdxNetApi;

    @Inject
    public PsdAdminPresenter(GsdxNetApi gsdxNetApi) {
        this.gsdxNetApi = gsdxNetApi;
        this.mNetworkDateSource = NetworkDateSources.getInstance();
    }


    @Override
    public void getGestureIsOpen() {
        final String access_token = ACache.get(DaggerApplication.getIns()).getAsString("access_token");
        if (StringUtils.isBlank(access_token)) {
            return;
        }
        IBaseRequest baseRequest = new IBaseRequest();
        baseRequest.setAccess_token(access_token);
        mNetworkDateSource.gestureValid(baseRequest, new SubscribeResult<GestureValidBean>() {
            @Override
            protected void onOk(GestureValidBean response) {
                Constant.isOpen = response.getIsOpen();
                ((IPasAdminContact.IPsdAdminView) mView).getGestureIsOpenSucc(response);
            }

            @Override
            protected void onFailure(GestureValidBean response) {
                super.onFailure(response);
                ((IPasAdminContact.IPsdAdminView) mView).getGestureIsOpenFail(response);
            }

            @Override
            protected void onNext(GestureValidBean response) {
                super.onNext(response);
                ((IPasAdminContact.IPsdAdminView) mView).getGestureIsOpenFail(response);
            }
        }, new ErrorAction() {
            @Override
            public void onCall(Throwable throwable) {
            }
        });
    }
}
